package springboot.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

@Repository

public class RolePermissionDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public List<Integer> getPermissionByRoleId(int role_id){
        String sql = "select * from rolepermission where role_id = ?";
        List<Integer> pIds = jdbcTemplate.query(sql,new RowMapper<Integer>() {
            @Override
            public Integer mapRow(ResultSet rs, int rowNum) throws SQLException {
                int pid = rs.getInt("permission_id");
                return pid;
            }
        },role_id);
        if (pIds.size()>0){
            return pIds;
        }else{
            return null;
        }
    }
}
